<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<script type="text/javascript">
get_check = function(){
	var ids = '';
	$("#list").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			if (ids)
			{
				ids += ',';
			}
			ids += $(this).val();
		}
	});
	return ids;
}
$(function(){
	$(".detail").colorbox({width:"75%", height:"80%", iframe:true});
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$("a[rel^='pretty_photo']").prettyPhoto({theme:'facebook'});
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
				$(".list_table input[type='checkbox']:enabled").attr("checked", true);
		}
		else
		{
			$(".list_table input[type='checkbox']").attr("checked", false);
		}
	});
	$("#start_btn").click(function(){
		var ids = get_check();
		if( ! ids)
		{
			alert('请选择调拨单！')
			return false;
		}
		if ( ! confirm('确定起始仓出库？'))
		{
			return false;
		}
		window.location.href=("<?=url('Storage::Allocate/ChangeNewToConfirm', array(Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>&ids=" + ids);
	});
	$("#return_btn").click(function(){
		var ids = get_check();
		if ( ! ids)
		{
			alert('请选择调拨单！');
		}
		if ( ! confirm('确定调拨返回起始仓库？'))
		{
			return false;
		}
		window.location.href=("<?=url('Storage::Allocate/ChangeConfirmToReturn')?>&ids=" + ids);
	});
	$("#end_btn").click(function(){
		var ids = get_check();
		if( ! ids)
		{
			alert('请选择调拨单！')
			return false;
		}
		if ( ! confirm('确定目标仓入库？'))
		{
			return false;
		}
		window.location.href=("<?=url('Storage::Allocate/ChangeConfirmToArrive', array(Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>&ids=" + ids);
	});
	$("#delete_btn").click(function(){
		var ids = get_check();
		if( ! ids)
		{
			alert('请选择调拨单')
			return false;
		}
		if ( ! confirm('确定删除所选调拨单？'))
		{
			return false;
		}
		window.location.href=("<?=url('Storage::Allocate/Delete', array(Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>&ids=" + ids);
	});
	$("#print_product_barcode_btn").click(function(){
		var ids = get_check();
		if (! ids)
		{
			alert("请选择调拨单");
			return false;
		}
		window.open("<?=url('Storage::Allocate/PrintPurchaseProductBarcode')?>&ids=" + ids);
	});
});
</script>
<fieldset><legend>查询条件</legend>
<form method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>制单日期</th>
	<td>
		<input type="text" class="datepicker" name="begin_create_time" value="<?=isset($_GET['begin_create_time'])?$_GET['begin_create_time']:''?>" /> to 
		<input type="text" class="datepicker" name="end_create_time" value="<?=isset($_GET['end_create_time'])?$_GET['end_create_time']:''?>" />
	</td>
</tr>
<tr>
	<th>调拨确认日期</th>
	<td>
		<input type="text" class="datepicker" name="begin_confirm_time" value="<?=isset($_GET['begin_confirm_time'])?$_GET['begin_confirm_time']:''?>" /> to 
		<input type="text" class="datepicker" name="end_confirm_time" value="<?=isset($_GET['end_confirm_time'])?$_GET['end_confirm_time']:''?>" />
	</td>
</tr>
<tr>
	<th>到仓确认日期</th>
	<td>
		<input type="text" class="datepicker" name="begin_arrive_time" value="<?=isset($_GET['begin_arrive_time'])?$_GET['begin_arrive_time']:''?>" /> to 
		<input type="text" class="datepicker" name="end_arrive_time" value="<?=isset($_GET['end_arrive_time'])?$_GET['end_arrive_time']:''?>" />
	</td>
</tr>
<tr>
	<th>财务审核日期</th>
	<td>
		<input type="text" class="datepicker" name="begin_finance_audit_time" value="<?=isset($_GET['begin_finance_audit_time'])?$_GET['begin_finance_audit_time']:''?>" /> to 
		<input type="text" class="datepicker" name="end_finance_audit_time" value="<?=isset($_GET['end_finance_audit_time'])?$_GET['end_finance_audit_time']:''?>" />
	</td>
</tr>
<tr>
	<th>产品信息</th>
	<td><input type="text" name="product" value="<?=isset($_GET['product'])?$_GET['product']:''?>" /></td>
</tr>
<tr>
	<th>调拨单号</th>
	<td><input type="text" name="number" value="<?=isset($_GET['number'])?$_GET['number']:''?>" /></td>
</tr>
<tr>
	<th>起始仓</th>
	<td>
		<select name="start_warehouse_id" id="start_warehouse">
			<option value="">请选择..</option>
			<?foreach ($warehouse as $w):?>
			<option value="<?=$w['id']?>" <?if(isset($_GET['start_warehouse_id']) && $_GET['start_warehouse_id'] == $w['id'])echo "selected='selected'"?>><?=$w['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>目标仓</th>
	<td>
		<select name="end_warehouse_id" id="end_warehouse">
			<option value="">请选择..</option>
			<?foreach ($warehouse as $w):?>
			<option value="<?=$w['id']?>" <?if(isset($_GET['end_warehouse_id']) && $_GET['end_warehouse_id'] == $w['id'])echo "selected='selected'"?>><?=$w['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>财务审核</th>
	<td>
		<?foreach (Q::ini('custom_flag/warehouse_allocate_finance_audit') as $f):?>
		<label><input type="checkbox" name="finance_audit[<?=$f['value']?>]" value="<?=$f['value']?>" <?=isset($_GET['finance_audit']) && in_array($f['value'], $_GET['finance_audit']) ? 'checked="checked"' : ''?>> <?=$f['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>调拨单状态</th>
	<td>
		<?foreach (Q::ini('custom_flag/warehouse_allocate_status') as $s):?>
		<label><input type="checkbox" name="warehouse_allocate_status[<?=$s['value']?>]" value="<?=$s['value']?>" <?=isset($_GET['warehouse_allocate_status']) && in_array($s['value'], $_GET['warehouse_allocate_status']) ? 'checked="checked"' : ''?>> <?=$s['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<td></td>
	<td><input type="submit" class="button" value="查询" /></td>
</tr>
</table>
</form></fieldset>

<table width="100%" class="list_table" id="list">
<tr>
	<th width="30"></th>
	<th width="120">单号</th>
	<th width="90">状态</th>
	<th width="60">起始仓</th>
	<th width="60">目标仓</th>
	<th width="150">制单日期</th>
	<th width="150">起始仓出库时间</th>
	<th width="150">调返起始仓时间</th>
	<th width="150">目标仓入库时间</th>
	<th width="70">制单人员</th>
	<th width="110">财务审核</th>
	<th width="180">备注</th>
	<th width="175">操作</th>
</tr>
<?foreach ($warehouse_allocate as $wa):?>
<tr>
	<td><label><input type="checkbox" value="<?=$wa['id']?>"/></label></td>
	<td><a class="detail" href="<?=url('Storage::Allocate/Detail', array('id'=>$wa['id']))?>" ><?=$wa['number']?></a></td>
	<td><?=Helper_BSS_Normal::getIniOne('warehouse_allocate_status', 'value', $wa['status'], 'name')?></td>
	<td><?=$wa['start_warehouse_name']?></td>
	<td><?=$wa['end_warehouse_name']?></td>
	<td title="制单日期: <?=$wa['make_time']?> <?=$wa['make_user_name']?>"><?=substr($wa['make_time'], 0, 10)?></td>
	<td title="起始仓出库时间: <?=$wa['confirm_time']?> <?=$wa['confirm_user_name']?>"><?=substr($wa['confirm_time'], 0, 10)?></td>
	<td title="调返起始仓时间: <?=$wa['return_time']?> <?=$wa['return_user_name']?>"><?=substr($wa['return_time'], 0, 10)?></td>
	<td title="目标仓入库时间: <?=$wa['arrive_time']?> <?=$wa['arrive_user_name']?>"><?=substr($wa['arrive_time'], 0, 10)?></td>
	<td><?=$wa['make_user_name']?></td>
	<td><?=Helper_BSS_Normal::getIniOne('warehouse_allocate_finance_audit', 'value', $wa['finance_audit'], 'name')?></td>
	<td align="left"><?=$wa['notes']?></td>
	<td>
		<a class="detail" href="<?=url('Storage::Allocate/Detail', array('id'=>$wa['id']))?>" >查看</a>
		<?if ($wa['status'] != Q::ini('custom_flag/warehouse_allocate_status/arrived/value')):?>
			<?if ($wa['status'] == Q::ini('custom_flag/warehouse_allocate_status/new/value')):?>
			<a href="<?=url('Storage::Allocate/Edit', array('id'=>$wa['id']))?>">编辑</a>
			<a href="<?=url('Storage::Allocate/Delete', array('ids' => $wa['id'], Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>" onclick="if (! confirm('确定删除？')) return false;">删除</a>
			<a href="<?=url('Storage::Allocate/ChangeNewToConfirm', array('ids' => $wa['id'], Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>" onclick="if (! confirm('确定出库起始仓？')) return false;">起始仓出库</a>
			<?elseif ($wa['status'] == Q::ini('custom_flag/warehouse_allocate_status/confirmed/value')):?>
			<a href="<?=url('Storage::Allocate/ChangeConfirmToReturn', array('ids' => $wa['id']))?>" onclick="if (! confirm('确定调拨返回起始仓库？')) return false;">调返起始仓</a>
			<a href="<?=url('Storage::Allocate/ChangeConfirmToArrive', array('ids' => $wa['id'], Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>" onclick="if (! confirm('确定已到仓，入库目标仓？')) return false;">目标仓入库</a>
			<?endif;?>
		<?endif;?>
	</td>
</tr>
<?endforeach;?>
</table>
<?=$page?>
<table class="list_table">
<tr>
<td rowspan="5"><label><input type="checkbox" id="check_all" /> 全选</label></td>
<td align="left">按勾选操作：
<input type="button" class="button" value="起始仓出库" id="start_btn" /> |
<input type="button" class="button" value="调返起始仓" id="return_btn" /> |  
<input type="button" class="button" value="目标仓入库" id="end_btn" /> | 
<input type="button" class="button" value="批量删除" id="delete_btn" />
</td>
</tr>
<tr>
	<td align="left">按勾选打印：
	<input type="button" value="FBA条形码" class="button" id="print_product_barcode_btn" />
	</td>
</tr>
</table>
<?php $this->_endblock();?>